import router from './router';
import { getToken } from '@/utils/auth' // 验权
import { AlertModule } from 'vux'
const whiteList = ['/login',
  '/register', '/register/validateMobile', '/register/submitInfo',
  '/resetPwd', '/resetPwd/validateMobile', '/resetPwd/submitInfo',
  '/home', '/'];

/**
 * @author:wesley.wu
 * @param: mod
 * @time: 2018/5/1 13:52
 * @Description: 注册一个全局前置守卫
 */
router.beforeEach((to, from, next) => {
  console.log("token:"+getToken())
  if (getToken()) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    console.log('-------------------->>>>>>>>>>>>>>')
    console.log(from.path)
    console.log(to.path)
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next('/login')
      AlertModule.show({
        title: '提示',
        content: '您的登录已过期，请重新登录！'
      })
    }
  }
})
